class Sprite extends ElementWindow 
{ 
  bool loaded = false;
  int hFlip = 1;
  int vFilp = 1;
  
  static Map<String, ImageElement> _loadedImages;
  static Map<String, ImageElement> get loadedImages()
  {
    if(_loadedImages == null)
    {
      _loadedImages = new Map<String, ImageElement>();
    }
    return _loadedImages;
  }
  
  static ImageElement getImage(String src)
  {
    if(loadedImages.containsKey(src))
    {
      return loadedImages[src];
    }
    else
    {
      ImageElement img = new Element.tag('img');
      img.src = src;
      loadedImages[src] = img;
      return img;
    }
  }

  Sprite(String src):super()
  {
    this.element = getImage(src);
  }
  
  void draw()
  {
    CanvasWindow parentCanvas = getParentCanvas();
    parentCanvas.context.drawImage(this.element, getX(), getY());    
  } 
}

